if (SERVER) then

	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
	SWEP.HoldType			= "shotgun"

end

if ( CLIENT ) then

	SWEP.ViewModelFOV		= 75
	
	SWEP.IconFont = "CSSelectIcons"
	
	SWEP.PrintName = "Ruger 77"
	SWEP.Slot = 4
	SWEP.Slotpos = 1
	SWEP.IconLetter = "B"
	
	killicon.AddFont( "weapon_ruger77_sh", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )

end

 SWEP.Base				= "tp_base"
 
 SWEP.IronSightsPos = Vector (5.1329, -1.1235, 1.3099)
 SWEP.IronSightsAng = Vector (1.4967, 0.8503, -0.9776)

 SWEP.Spawnable = true;
 SWEP.AdminSpawnable = true;

 SWEP.ViewModel			= "models/weapons/v_shot_xm1014.mdl"
 SWEP.WorldModel			= "models/weapons/w_shot_xm1014.mdl"

 SWEP.Primary.Sound			= Sound( "weapons/scout/scout_fire-1.wav" )
 SWEP.Primary.Sound2		= Sound( "npc/sniper/sniper1.wav" )
 SWEP.Primary.Recoil			= 3.1
 SWEP.Primary.Damage			= 90
 SWEP.Primary.NumShots		      = 1
 SWEP.Primary.Cone			= 0.024
 SWEP.Primary.ClipSize              = 4
 SWEP.Primary.Delay			= 0.8
 SWEP.Primary.Automatic             = false
 SWEP.Primary.Ammo                  = "buckshot"

 SWEP.Secondary.Clipsize            = -1;
 SWEP.Secondary.DefaultClip         = -1;
 SWEP.Secondary.Automatic           = false
 SWEP.Secondary.Ammo                = "none"; 
 SWEP.Secondary.Delay			= 4


function SWEP:PrimaryAttack()

	if ( self.Weapon:Clip1() <= 0 ) then 
		self.Weapon:EmitSound(Sound("weapons/shotgun/shotgun_empty.wav"),100,math.random(90,110)) 
		if ( self.Weapon:GetNetworkedBool( "reloading", true ) ) then return end

		if ( self.Weapon:Clip1() <= self.Primary.ClipSize ) then
		
			self.Weapon:SetNetworkedBool( "Ironsights", false )
			self.Weapon:SetNetworkedBool( "reloading", true )
			self.Weapon:SetVar( "reloadtimer", CurTime() + 0.5 )
			self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START )
		
		end
	return end
	
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	if  !self:CanPrimaryAttack()  then return end
	
	self:ShootBullets( self.Primary.Damage, self.Primary.NumShots, self.Primary.Cone)
	self.Owner:ViewPunch(Angle(math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0))
	self.Weapon:EmitSound(self.Primary.Sound,100,math.random(80,90))
	self.Weapon:EmitSound(self.Primary.Sound2,100,math.random(80,90))
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self:TakePrimaryAmmo(1)
	self.Weapon:SetRecoilTime(CurTime() + .3)
end

function SWEP:Deploy()
	self.Weapon:SetNetworkedBool( "reloading", false )
end

function SWEP:Reload()
	if self.Owner:GetNWInt("ammo_"..self.Primary.Ammo, 0) <= self.Weapon:Clip1() then return end
	if self.Owner:GetNWInt("ammo_"..self.Primary.Ammo, 0) <= 0 then return end
	if ( self.Weapon:GetNetworkedBool( "reloading", true ) ) then return end
	if ( self.Weapon:Clip1() <= self.Primary.ClipSize ) then
		self.Weapon:SetNetworkedBool( "Ironsights", false )
		self.Weapon:SetNetworkedBool( "reloading", true )
		self.Weapon:SetVar( "reloadtimer", CurTime() + 0.5 )
		self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START )
	end
return true end

function SWEP:Think()
	if ( self.Weapon:GetNetworkedBool( "reloading", false ) ) then
		if ( self.Weapon:GetVar( "reloadtimer", 0 ) < CurTime() ) then
			
			// Finsished reload
			local size = math.min(self.Owner:GetNWInt("ammo_"..self.Primary.Ammo, 0),self.Primary.ClipSize)
			local clip1 = self.Weapon:Clip1() or 0
			if ( clip1 == size ) then
				self.Weapon:SetNetworkedBool( "reloading", false )
				self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH )
				return
			end
			
			// Next cycle
			self.Weapon:SetVar( "reloadtimer", CurTime() + 0.4 )
			self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
			self.Weapon:SetNextPrimaryFire( CurTime() + 0.55 )
			
			// Add ammo
			local clip = self.Weapon:Clip1()
			self.Weapon:SetClip1(  clip + 1 )
			
		end
	end
end